import InteractiveBase from "../../../LevelCommon/InteractiveBase";
import LevelBaseControl from "../../../LevelCommon/LevelBaseControl";
import RotateObj from "../Common/RotateObj";
import GamePropConst from "../../../../constant/GamePropConst";

export default class CoinMachine extends InteractiveBase {
    /** 当前所有的硬币位置*/
    public curAllCoin: Array<Laya.Sprite3D> = new Array<Laya.Sprite3D>();
    /** 当前放上的硬币数*/
    private curPutNum: number = 0;
    private curLevelControl: LevelBaseControl;
    /** 盖子*/
    private gaizi: RotateObj;
    private mowner: Laya.Sprite3D;
    onStart() {
        this.mowner = this.owner as Laya.Sprite3D;
        this.curLevelControl = window.gameFacade.LevelMng.GetCurLevelControl();
        this.gaizi = this.mowner.getChildByName("gaizi").getComponent(RotateObj);
    }
    protected InteractiveLogic(): boolean {
        if (this.curLevelControl.IsSelectProp(GamePropConst.coin_prop)) {
            /** 消耗硬币 放上去*/
            this.curLevelControl.UseCurProp();
            this.curAllCoin[this.curPutNum].active = true;
            this.curPutNum++;
            /** 检测是否放完了*/
            if (this.curPutNum == this.curAllCoin.length) {
                /** 盖子打开*/
                this.gaizi.Interactive();
            }
        }
        return false;
    }
}